<template>
  <transition
    enter-to-class="animate__animated animate__fadeInRight"
    enter-active-class="animate__animated animate__fadeInRight"
    leave-to-class="animate__animated animate__fadeOutDown"
    leave-active-class="animate__animated animate__fadeOutDown"
  >
    <div class="web-qingdan">
      <app-return></app-return>
      <div class="form">
        <input type="text" placeholder="名称" />
      </div>
      <nav>
        <ul>
          <li v-for="(item, index) in arr" :key="item.id">
            <span>□</span>
            <input placeholder="键入清单" type="text" />
            <button
              @click="myRemove(index)"
              >
              ×
            </button>
          </li>
        </ul>
      </nav>
      <div class="add"><button @click="addLi">+</button>清单项</div>
    </div>
  </transition>
</template>

<script>
import AppReturn from "@/components/app-return.vue";
export default {
  name: "qiandan",
  components: {
    AppReturn,
  },
  data() {
    return {
      arr: [{ name: 0 }]
    };
  },
  watch: {
    arr(v) {
      // console.log(v);
      this.newArr = v;
      // console.log(this.newArr);
    },
  },
  methods: {
    addLi() {
      let obj = {};
      obj.name = this.arr.length;
      obj.id = Math.random();
      this.arr.push(obj);
      // console.log(this.arr);
      // console.log(obj.id);
    },
    myRemove(index) {
      this.arr.splice(index, 1);
      // console.log(index);
    },
  },
};
</script>

<style lang="less" scoped>
.web-qingdan {
  box-sizing: border-box;
  padding: 50px 15px 0;
  .form {
    width: 100%;
    height: 40px;
    margin-bottom: 20px;
    input {
      width: 100%;
      height: 100%;
      font-size: 16px;
    }
  }
  nav {
    width: 100%;
    margin-bottom: 20px;
    ul {
      width: 100%;
      li {
        width: 100%;
        display: flex;
        margin-bottom: 10px;
        justify-content: space-between;
        span {
          font-size: 20px;
          vertical-align: middle;
        }
        input {
          vertical-align: middle;
          flex-grow: 1;
          padding-left: 10px;
          font-size: 15px;
        }
        button {
          vertical-align: middle;
          background-color: transparent;
          font-size: 26px;
        }
      }
    }
  }
  .add {
    width: 100%;
    font-size: 18px;
    color: #808080;
    button {
      font-size: 25px;
      background-color: transparent;
      vertical-align: middle;
      margin-top: -2px;
    }
  }
}
</style>